import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:skeletons/skeletons.dart';

import '../../../routes/app_pages.dart';
import '../controllers/group_info_controller.dart';

class GroupInfoView extends GetView<GroupInfoController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('群信息'),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Obx(() => Container(
              child: controller.groupInfo.value.id != null
                  ? Column(
                      children: [
                        ListTile(
                          title: Text("群聊名称:"),
                          subtitle: Text(controller.groupInfo.value.name!),
                          trailing:
                              controller.userInfoService.userInfo.value.id ==
                                      controller.groupInfo.value.userId
                                  ? GestureDetector(child: Icon(Icons.edit), onTap: () {
                                    controller.toEditGroupName();
                              },)
                                  : null,
                        ),
                        ListTile(
                          title: Text("群号:"),
                          subtitle: Text("group_chat_" +
                              controller.groupInfo.value.id!.toString()),
                        ),
                        ListTile(
                            title: Text("群公告:"),
                            subtitle: Text(controller.groupInfo.value.notice!),
                            trailing:
                                controller.userInfoService.userInfo.value.id ==
                                        controller.groupInfo.value.userId
                                    ? GestureDetector(child: Icon(Icons.edit), onTap: () {
                                  controller.toEditGroupNotice();
                                },)
                                    : null),
                        ListTile(
                          title: Text("群主:"),
                          subtitle:
                              Text(controller.groupInfo.value.userId!.toString()),
                        ),
                        ListTile(
                          title: Text("群聊成员:"),
                          subtitle: Container(
                            constraints: BoxConstraints(maxHeight: 120),
                            child: ListView(

                                scrollDirection: Axis.horizontal,
                              children: controller.memberList.map((id) {
                                return GestureDetector(
                                  onTap: () {
                                    Get.toNamed(Routes.OTHER_PROFILE, arguments: id);
                                  },
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(
                                      children: [
                                        CircleAvatar(
                                          radius: 12,
                                          backgroundImage: controller.userInfoService
                                                      .avatarMap[id]! !=
                                                  ""
                                              ? NetworkImage(controller
                                                  .userInfoService.avatarMap[id]!)
                                              : null,
                                        ),
                                        Text(
                                          id.toString(),
                                          style: TextStyle(fontSize: 12),
                                        )
                                      ],
                                    ),
                                  ),
                                );
                              }).toList(),
                            ),
                          ),
                        ),
                      ],
                    )
                  : SkeletonListView(),
            )),
      ),
    );
  }
}
